package com.m4f.web.interceptor;

import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.servlet.ServletRequestContext;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;


public class FileUploadInterceptor extends HandlerInterceptorAdapter {
	
	private static final Logger LOGGER = Logger.getLogger(FileUploadInterceptor.class.getName());
	
	public boolean preHandle(HttpServletRequest request,
	            HttpServletResponse response, Object handler) throws Exception {
			ServletRequestContext sRC = new ServletRequestContext(request);
			LOGGER.severe("***********************************************");
			LOGGER.severe("**** Content Lenght: " + sRC.getContentLength());
			LOGGER.severe("***********************************************");
			LOGGER.severe("***********************************************");
			LOGGER.info("Before handling the request");
			LOGGER.info("Handler class: " + handler.getClass());
			response.sendRedirect("/efqm/home?av=false");
			//response.sendRedirect("/availability?av=false");
			return false;
	        //return super.preHandle(request, response, handler);
	    }
	     
	   
	    public void postHandle(HttpServletRequest request,
	            HttpServletResponse response, Object handler,
	            ModelAndView modelAndView) throws Exception {
	    	LOGGER.info("After handling the request");
	        super.postHandle(request, response, handler, modelAndView);
	    }
	     
	   
	    public void afterCompletion(HttpServletRequest request,
	            HttpServletResponse response, Object handler, Exception ex)
	            throws Exception {
	    	LOGGER.info("After rendering the view");
	        super.afterCompletion(request, response, handler, ex);
	    }

	    

}